package net.maku.controller;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.service.payments.app.AppServiceExtension;
import com.wechat.pay.java.service.payments.app.model.Amount;
import com.wechat.pay.java.service.payments.app.model.PrepayRequest;
import com.wechat.pay.java.service.payments.app.model.PrepayWithRequestPaymentResponse;





public class AppQuickStart {
	/** 商户号 */
	  public static String appid = "wx6ed1af0b9fdd0456";
	  //APPID：wx1574a5cc73751091
	  //mch_id：1676811007

	
	  /** 商户号 */
	  public static String merchantId = "1676811007";

	  /** 商户API私钥路径 */
	  //public static String privateKeyPath = "D:\\workspaces\\workspace202409\\duxinai-end\\cert\\apiclient_cert.p12";
	  public static String privateKeyPath = "D:\\workspaces\\workspace202409\\duxinai-end\\cert\\apiclient_key.pem";

	  
	  /** 商户证书序列号 */
	  public static String merchantSerialNumber = "3C8BB16E5EDCBDF6C814AC5276F239401AC401D3";

	  /** 商户APIV3密钥 */
	  public static String apiV3Key = "oXi4b7pE7YU5QRXCHC30tx5yfXJCAyyC";
	  
	  
	  
	  public static void main(String[] args) {
		  
		  
		// 初始化商户配置
		    Config config =
		        new RSAAutoCertificateConfig.Builder()
		            .merchantId(merchantId)
		            // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥，商户私钥会用来生成请求的签名
		            .privateKeyFromPath(privateKeyPath)
		            .merchantSerialNumber(merchantSerialNumber)
		            .apiV3Key(apiV3Key)
		            .build();
		    // 初始化服务
		    AppServiceExtension service = new AppServiceExtension.Builder().config(config).build();
		    try {
		      // ... 调用接口
		      PrepayRequest request = new PrepayRequest();
		      Amount amount = new Amount();
			    amount.setTotal(100);
			    //request.setAmount(amount);
			    //request.setAppid(appid);
			    //request.setMchid(merchantId);
			    
			    request.setAmount(amount);
			    request.setAppid(appid);
			    request.setMchid(merchantId);
			    //request.setSpAppid(appid);
			    //request.setSpMchid(merchantId);
			    //request.setSubAppid(appid);
			    //request.setSubMchid(merchantId);
			    request.setDescription("测试商品标题");
			    request.setNotifyUrl("https://notify_url");

			    /** 商户订单号 说明：商户订单号 */
			    request.setOutTradeNo("out_trade_no_001");
			    PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request);
			    //Payer payer = new Payer();
			    //payer.setOpenid("oyiCY7ZI5zONxJ3f-O_eoV-N1naw");
			    //request.setPayer(payer);
			    
		      //PrepayWithRequestPaymentResponse response = service.prepayWithRequestPayment(request,appid );
 
		      System.out.println(response);
		    } catch ( Exception e) { // 发送HTTP请求失败
		      // 调用e.getHttpRequest()获取请求打印日志或上报监控，更多方法见HttpException定义
		    	e.printStackTrace();
		    } 
		  
		  
		  
	  }
	  
	  
}





